package hash;

public enum Checksums {

	MD5, SHA1;
	
	/** Checksum Regex */
	static String md5 = "<MD5>(.*?)</MD5>";
	static String sha1 = "<SHA1>(.*?)</SHA1>";
	
	
	/**
	 * Strip Checksum tags from string
	 * <p>
	 * @param str - String to strip tags from
	 * @return - String with tags striped
	 */
	public static String stripTags(String str)
	{
		return str.replaceAll("\\<.*?\\>", "").trim();
	}
	
	
	/**
	 * Add Checksum tags to string.
	 * <p>
	 * @param str - String to add tags too
	 * @param checksumType - Checksum type tags to add to string
	 * @return - String with tags
	 */
	public static String buildTags(String str, Checksums checksumType)
	{
		switch (checksumType)
		{
		case MD5: return "<MD5>" + str + "</MD5>";			
		case SHA1: return "<SHA1>" + str + "</SHA1>";			
		}
		return null;
	}
	
	/**
	 * Match string based on regex for checksum type.
	 * <p>
	 * @param str - String to match
	 * @return - CHechsum type
	 */
	public static Checksums matchType(String str)
	{		
		if (str.matches(md5)) return MD5;			
		if (str.matches(sha1)) return SHA1;
		return null;		
	}
}
